<?php

session_start();

$customer_id = $_SESSION['userid'];

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Second Hand General Purpose Horse Saddles | Lancashires Used Horse Saddles - 24-7 Saddles</title>

<link href="css/header.css" rel="stylesheet" type="text/css">
<link href="css/navigation.css" rel="stylesheet" type="text/css" />
<link href="css/products.css" rel="stylesheet" type="text/css" />
<link href="css/paginate.css" rel="stylesheet" type="text/css" />
<link href="css/products_product.css" rel="stylesheet" type="text/css" />

<style type="text/css">
body {
	background-image: url(images/wood.jpg);
	background-repeat: repeat-x;
	margin: 0px;
	background-position: left top;
	background-attachment: fixed;
	background-color: #000000;
	padding-top: 0px;
	padding-right: 0px;
	padding-bottom: 0px;
	padding-left: 0px;
}
</style>
</head>

<body>

<div id="page_container">

<?php include "header.php" ?>

<?php include "navigation.php" ?>

<!-- HIDDEN

<div id="search_container">

<form action="xxx" method="post" name="search_products_form" class="label_product_type">

<label>Product type:</label>

<select id="product_type_select" name="product_type">
  <option value="saddle">Saddles</option>
  <option value="equipment">Equipment</option>
</select>

<label>Product catagory:</label>

<select id="product_type_select" name="product_type">
  <option value="gp_saddles">GP Saddles</option>
  <option value="jump_saddles">Jump Saddles</option>
</select>

<label>Product colour:</label>

<select id="product_type_select" name="product_type">
  <option value="gp_saddles">Brown</option>
  <option value="jump_saddles">Black</option>
</select>

<input id="search_products_button" name="search_products_button" type="button" value="Search" />

</form>

</div>

-->

<!--search_container-->

<div id="product_details_container">


<?php
	include('connect.php');	
	
	$tableName="saddles";		
	$targetpage = "products.php"; 	
	$limit = 3; 
	
	$query = "SELECT COUNT(*) as num FROM $tableName";
	$total_pages = mysql_fetch_array(mysql_query($query));
	$total_pages = $total_pages[num];
	
	$stages = 3;
	$page = mysql_escape_string($_GET['page']);
	if($page){
		$start = ($page - 1) * $limit; 
	}else{
		$start = 0;	
		}	
	
    // Get page data
	$query1 = "SELECT * FROM $tableName LIMIT $start, $limit";
	$result = mysql_query($query1);
	
	// Initial page num setup
	if ($page == 0){$page = 1;}
	$prev = $page - 1;	
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$LastPagem1 = $lastpage - 1;					
	
	
	$paginate = '';
	if($lastpage > 1)
	{	
	

	
	
		$paginate .= "<div class='paginate'>";
		// Previous
		if ($page > 1){
			$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
		}else{
			$paginate.= "<span class='disabled'>previous</span>";	}
			

		
		// Pages	
		if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
			}
		}
		elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
		{
			// Beginning only hide later pages
			if($page < 1 + ($stages * 2))		
			{
				for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
			}
			// Middle hide some front and some back
			elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
			{
				$paginate.= "<a href='$targetpage?page=1'>1</a>";
				$paginate.= "<a href='$targetpage?page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
			}
			// End only hide early pages
			else
			{
				$paginate.= "<a href='$targetpage?page=1'>1</a>";
				$paginate.= "<a href='$targetpage?page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
				}
			}
		}
					
				// Next
		if ($page < $counter - 1){ 
			$paginate.= "<a href='$targetpage?page=$next'>next</a>";
		}else{
			$paginate.= "<span class='disabled'>next</span>";
			}
			
		$paginate.= "</div>";		
	
	
}

 // pagination
 echo "<div id='paginate_container'>";
 echo $paginate;
 echo "</div>";
 
?>

<?php 

	echo "<div id='new_products_container'>";
	
	echo "<ul>";

	while($row = mysql_fetch_array($result))
	 
	 {
		 
		 
	$product_name = $row['product_name'];
	$product_status = $row['product_status'];	
	$product_cost = $row['product_cost']; 
	$product_description = $row['product_description'];
	$product_id = $row['product_id'];
	$product_row_id = $row['id'];
	$product_offer = $row['product_offer'];
	
	echo '<li>';
	echo '<form action="product_details.php" method="post" name="product">';
	echo '<img id="product_imgage_large" src="images/saddles/1_1.jpg" width="500" height="500" />';
	echo '<h4>'.$product_row_id.'</h4>';
	
	if($product_status == "On-trial") //if saddle is on trial
	{
	echo '<p id="ontrial_banner">On-trial</p>';
	}
	
	if($product_status != "On-trial") //if saddle isnt on trial
	{
		if($product_offer != "") //if saddle has is on offer
		{
			echo '<p id="product_banner">'.$product_offer.'</p>';
		}
		
		if($product_offer == "") //if saddle isnt on offer
		{
			echo '';
		}
	}
	
	echo '<p id="product_price"><i>Only</i> £'.$product_cost.'</p>\n';
	echo '<p id="product_description">'.$product_description.'</p>\n';
	echo '<input name="product_row_id" type="hidden" value="'.$product_row_id.'" />\n';
	echo '<input name="view_product" type="submit" class="product_button" value="More details" />\n';
	echo '<input name="view_product" type="button" class="product_button" value="Buy" />\n';
	echo '</form>\n';
		
			
	echo '<p id="product_price"><i>Product ID: '.$product_id.'</i></p>';
	echo '<li>';
	

	 }
	 
	 echo "</ul>";
	 
	 echo "</div>";
	
 //echo $paginate;
	
	?>

</div>
<!--product_details_container-->

</div> 
<!--page_container-->

<?php include "footer.php" ?>

</body>
</html>